using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb; 

namespace MaskMgr
{
    public partial class DatasetSettingFrm : Form
    {
        private OleDbConnection con;
        private OleDbDataAdapter dAdapter;
        private DataSet dSet;
        private string conString;
        public DatasetSettingFrm()
        {
            InitializeComponent();
            
        }
        private void btnTest_Click(object sender, EventArgs e)
        {
            conString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + buttonEdit1.Text;
            try
            {
                con = new OleDbConnection(conString);
                dAdapter = new OleDbDataAdapter("select * from login" , con);
                dSet = new DataSet();
                //refreshes rows in the DataSet 			
                dAdapter.Fill(dSet, "login");
                MessageBox.Show("connect success!\n");
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error : " + ex.Message);
            }	   

        }

        public DataSet GetDst(string tablename)
        {
            try
            {
                con = new OleDbConnection(conString);
                dAdapter = new OleDbDataAdapter("select * from " + tablename, con);
                dSet = new DataSet();
                //refreshes rows in the DataSet 			
                dAdapter.Fill(dSet, tablename);
               // MessageBox.Show("connect success!\n");
                return dSet;
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error : " + ex.Message);
                return null;
            }
        }

        public void UpdateTable(string Tablename, DataSet dset)
        {
            OleDbDataAdapter TempdAdapter;
            if (Tablename == "picture")
            {
                TempdAdapter = new OleDbDataAdapter("select * from picture", con);
            }
            else
                TempdAdapter = new OleDbDataAdapter("select * from try", con);
            OleDbCommandBuilder CB = new OleDbCommandBuilder(TempdAdapter);
            TempdAdapter.Update(dset, Tablename);
        }
    }
}